import os
import sys
import pandas as pd
from PyQt5.QtWidgets import QApplication
from src.backend.db.database import SQLite

if getattr(sys, 'frozen', False):
    # 如果是打包后的 .exe 文件
    exe_dir = os.path.dirname(sys.executable)
else:
    # 如果是在开发环境中运行
    exe_dir = os.getcwd()
# 指定数据库文件的路径
db_dir = exe_dir + '/db'
image_dir = exe_dir + '/image'
handout_dir = exe_dir + '/handout'
os.makedirs(exe_dir + '/db', exist_ok=True)
os.makedirs(exe_dir + '/handout', exist_ok=True)
os.makedirs(exe_dir + '/image', exist_ok=True)

db_path = os.path.join(db_dir, 'database.db')
word_path = exe_dir+'/word/math.xlsx'
sql = SQLite(db_path,handout_dir,word_path,image_dir)
df = pd.read_sql_query('select name from sqlite_master', sql.conn)
if len(df) == 0:
    sql.init_db()

from src.forward.base.bean import get_main_window

app = QApplication(sys.argv)
window = get_main_window()
window.show()
sys.exit(app.exec_())
